//
//  MKBusUnit.m
//  MKEnvObserver_Example
//
//  Created by liu nian on 2020/12/23.
//  Copyright © 2020 i19850511@gmail.com. All rights reserved.
//

#import "MKBusUnit.h"
#import <MKEnvObserver/MKEnvObserver.h>

@interface MKBusUnit ()<MKEnvObserverApplicationProtocol>
@property (nonatomic, strong, readwrite) MKEnvObserverCenter *obCenter;
@end
static id sharedInstance = nil;
static dispatch_once_t onceToken;

@implementation MKBusUnit

- (void)dealloc {
	MKRemoveApplicationObserver(self);
}

- (instancetype)init {
	self = [super init];
	if (self) {
		_obCenter = [[MKEnvObserverCenter alloc] init];
		MKAddApplicationObserver(self);
	}
	return self;
}

+ (instancetype)sharedInstance {
	dispatch_once(&onceToken, ^{
		sharedInstance = [[self alloc] init];
	});
	return sharedInstance;
}

+ (void)destroyInstance {
	sharedInstance = nil;
}

- (void)addObserver:(id<MKBusUnitProtocol>)observer {
    [_obCenter addEnvObserver:observer];
}

- (void)removeObserver:(id<MKBusUnitProtocol>)observer {
    [_obCenter removeEnvObserver:observer];
}

@end
